package com.snake.springboot.custom.controller.goods;

import com.snake.springboot.custom.api.model.goods.StrategyGoodsModel;
import com.snake.springboot.custom.api.model.goods.StrategyGoodsStateModel;
import com.snake.springboot.custom.api.request.goods.StrategyGoodsQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.response.goods.StrategyGoodsRsp;
import com.snake.springboot.custom.api.service.goods.StrategyGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>策略商品管理-策略商品信息
 * 类{@code StrategyGoods} </br>
 * 创建时间2025/3/27 16:13
 *
 * @author yangxt
 * @see
 */
@Api(tags = "策略商品管理-策略商品信息")
@RestController
@RequestMapping("/strategy/goods")
public class StrategyGoodsController {

    private StrategyGoodsService goodsService;
    @Autowired
    public StrategyGoodsController(StrategyGoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseResult<StrategyGoodsModel> addStrategyGoods(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) StrategyGoodsModel model) {
        StrategyGoodsModel result = goodsService.addStrategyGoods(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改")
    @PostMapping("/modify")
    public ResponseResult<StrategyGoodsModel> modifyStrategyGoods(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody StrategyGoodsModel model) {
        goodsService.modifyStrategyGoods(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public ResponseResult<Object> remove(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("id") String id) {
        goodsService.removeStrategyGoods(id);
        return ResponseResultFactory.ucc("移除成功！");
    }

    @ApiOperation("查询列表")
    @PostMapping("/list")
    public ResponseResult<ReturnList<StrategyGoodsModel>> queryStrategyGoodsList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<StrategyGoodsQuery> params) {
        ReturnList<StrategyGoodsModel> result = goodsService.queryStrategyGoodsList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public ResponseResult<StrategyGoodsRsp> detail(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("id") String id) {
        StrategyGoodsRsp rsp = goodsService.detail(id);
        return ResponseResultFactory.ucc("获取详情成功！",rsp);
    }

    @ApiOperation("更改上架状态")
    @PostMapping("/up-state")
    public ResponseResult<Object> upState(@RequestBody StrategyGoodsStateModel model) {
        goodsService.upState(model);
        return ResponseResultFactory.ucc("更改上架状态成功！");
    }


}
